package com.jiukuaidao.zhulin.util;

import android.content.SharedPreferences;

import com.jiukuaidao.zhulin.AppContext;
import com.jiukuaidao.zhulin.module.address.bean.PreAddressBean;

/**
 * Author : PaiTaSuo
 * Date : 2016/6/14
 * Description :
 */
public class AddressInfoUtil {

    /**
     * 保存地址信息
     */
    public static void saveAddressInfo(PreAddressBean addressInfo) {
        SharedPreferences.Editor editor = AppContext.getContext().getSharedPreferences("addressInfo", 0).edit();
        editor.putString("longitude", addressInfo.longitude);
        editor.putString("latitude", addressInfo.latitude);
        editor.putString("city", addressInfo.city);
        editor.putString("cityCode", addressInfo.cityCode);
        editor.putString("address", addressInfo.address);
        editor.commit();
    }

    /**
     * 获取地址信息
     *
     * @return
     */
    public static PreAddressBean getAddressInfo() {
        PreAddressBean addressInfo = new PreAddressBean();
        SharedPreferences addressData = AppContext.getContext().getSharedPreferences("addressInfo", 0);
        addressInfo.longitude = addressData.getString("longitude", "");
        addressInfo.latitude = addressData.getString("latitude", "");
        addressInfo.city = addressData.getString("city", "");
        addressInfo.cityCode = addressData.getString("cityCode", "");
        addressInfo.address = addressData.getString("address", "");
        return addressInfo;

    }

    /**
     * 清除地址信息
     */
    public static void cleanAddressInfo() {
        SharedPreferences.Editor addressData = AppContext.getContext().getSharedPreferences("addressInfo", 0).edit();
        addressData.clear();
        addressData.commit();
    }

}
